﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic.Web;
using LotteryVote.Entity;
using LotteryVote.Logic.Exceptions;
using LotteryVote.Logic;

namespace LotteryVote
{
    public partial class LoginLog : AuthorizePage
    {
        UserFacade userFacade = new UserFacade();
        public User TargetUser { get; private set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            Execute(() =>
            {
                InitParams();
            });
        }

        void InitParams()
        {
            int userId;
            if (string.IsNullOrEmpty(Request["UserId"]) || !int.TryParse(Request["UserId"], out userId))
                TargetUser = CurrentUser;
            else
            {
                TargetUser = userFacade.GetUser(userId);
                if (TargetUser == null || (TargetUser.UserId != CurrentUser.UserId && TargetUser.ParentId != CurrentUser.UserId))
                    throw new NoPermissionException("查看登录日志:UserId:" + userId);
            }
            if (!IsPostBack)
                BindLoginLog();
        }
        void BindLoginLog()
        {
            rpt_loginLog.DataSource = userFacade.ListUserLoginLog(TargetUser);
            rpt_loginLog.DataBind();
        }
    }
}